﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Shapes;

using SBPweb.RIA.Client.Controls.Base;

using SBPweb.PlAzureNet.Shared.Library.Actors;

using SBPweb.PlAzureNet.Client.Library;
using SBPweb.PlAzureNet.Client.Library.Controllers;

namespace SBPweb.PlAzureNet.Client.Library.Controls
{

    public partial class ActionsContent : UserControlBase
    {

        #region Fields

        #endregion

        #region Constructor logic

        public ActionsContent()
        {
            InitializeComponent();
        }

        #endregion

        #region Methods

        #endregion

        #region Event handlers

        protected override void OnLoaded(object sender, RoutedEventArgs e)
        {
            base.OnLoaded(sender, e);

            Type t = typeof(MainControl);
            ((tbbGive.ButtonContent as Grid).FindName("imgGive") as Image).Source = t.GetEmbeddedBitmapImage("Resources.Give_256x256.png");
            ((tbbPass.ButtonContent as Grid).FindName("imgPass") as Image).Source = t.GetEmbeddedBitmapImage("Resources.Pass_256x256.png");
            ((tbbTake.ButtonContent as Grid).FindName("imgTake") as Image).Source = t.GetEmbeddedBitmapImage("Resources.Take_256x256.png");

            icPleasures.ItemsSource = DataServiceController.Instance.Pleasures;
            icQuantity.ItemsSource = new uint[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 1000 };

            DataServiceController.Instance.FetchAllPleasures();
        }

        private void tbbGive_MouseClick(object sender, MouseButtonEventArgs e)
        {
            tbbGive.Opacity = 1.0;
            tbbPass.Opacity = 0.5;
            tbbTake.Opacity = 0.5;

            TrackingServiceController.Instance.Action.Request = ActionTypes.Give;
        }

        private void tbbPass_MouseClick(object sender, MouseButtonEventArgs e)
        {
            tbbGive.Opacity = 0.5;
            tbbPass.Opacity = 1.0;
            tbbTake.Opacity = 0.5;

            TrackingServiceController.Instance.Action.Request = ActionTypes.Pass;
        }

        private void tbbTake_MouseClick(object sender, MouseButtonEventArgs e)
        {
            tbbGive.Opacity = 0.5;
            tbbPass.Opacity = 0.5;
            tbbTake.Opacity = 1.0;

            TrackingServiceController.Instance.Action.Request = ActionTypes.Take;
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("hu-HU");
            System.Threading.Thread.CurrentThread.CurrentCulture = ci;
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

            DataServiceController.Instance.FetchAllPleasures();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
            System.Threading.Thread.CurrentThread.CurrentCulture = ci;
            System.Threading.Thread.CurrentThread.CurrentUICulture = ci;

            DataServiceController.Instance.FetchAllPleasures();
        }

        private void tbbQuantity_MouseClick(object sender, MouseButtonEventArgs e)
        {
            ToolBarButton tbb = (sender as Panel).Parent as ToolBarButton;
            TrackingServiceController.Instance.Action.RequestedQuantity = Convert.ToDecimal(tbb.DataContext);
        }

        private void tbbQuantity_MouseEnter(object sender, MouseEventArgs e)
        {
            Grid grd = sender as Grid;
            Point mP = grd.TransformToVisual(scvQuantity).Transform(new Point(0, 0));
            scvQuantity.ScrollToHorizontalOffset(mP.X);
        }

        private void tbbPleasure_MouseClick(object sender, MouseButtonEventArgs e)
        {
            ToolBarButton tbb = (sender as Panel).Parent as ToolBarButton;
            IPleasure pleasure = tbb.DataContext as IPleasure;
            TrackingServiceController.Instance.Action.PleasureId = pleasure.Id;
        }

        private void tbbPleasure_MouseEnter(object sender, MouseEventArgs e)
        {
            Grid grd = sender as Grid;
            Point mP = grd.TransformToVisual(scvPleasures).Transform(new Point(0, 0));
            scvPleasures.ScrollToHorizontalOffset(mP.X);
        }

        #endregion


        
    }

}